package com.gxa.controller;

import com.gxa.pojo.Advert;
import com.gxa.pojo.Am;
import com.gxa.pojo.ArticleClass;
import com.gxa.utils.Constants;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author bq
 * Date: 2020/11/25 21:01
 * Description:
 * Version: V1.0
 */
@Api(value = "文章控制类",tags = "文章控制类")
@RestController
@RequestMapping(value = "article")
public class ArticleController {
    @Autowired
    private ResponseData responseData;

    @GetMapping("queryArticle")
    @ApiOperation(value = "查询所有文章",notes = "查询所有文章",httpMethod = "GET", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=400,message="查询失败"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResponseData queryArticle(){
        List<Am> ams=new ArrayList<>();
        ArticleClass articleClass=new ArticleClass();
        articleClass.setArticleCid(1);
        articleClass.setArticleAs(Constants.APPROVED);
        articleClass.setArticleCc("这是一个贪玩蓝月的广告");
        articleClass.setArticleCname("贪玩蓝月");
        Am am1=new Am();
        am1.setAmId(1);
        am1.setAmAt("拼夕夕1");
        am1.setAmKw("夕夕");
        am1.setAmWpd("这是一个拼夕夕的文章");
        am1.setAmAc("大嘎好！我系渣渣辉，贪玩蓝月一个非常好玩的游戏。装备回收秒到账，一刀999。开服即送麒麟坐骑，装备全靠打，是兄弟就来贪玩蓝月砍我");
        am1.setAmDs(Constants.APPROVED);
        am1.setArticleCid(1);
        am1.setArticleClass(articleClass);
        try {
            am1.setAmAddtime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2012-10-10 16:32:23"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Am am2=new Am();
        am2.setAmId(2);
        am2.setAmAt("拼夕夕2");
        am2.setAmKw("夕夕2");
        am2.setAmWpd("这是一个关于拼夕夕的文章");
        am2.setAmAc("大嘎好！我系古天乐，贪玩蓝月真的非常非常好玩。我和渣渣辉都在贪玩蓝月等你哦");
        am2.setAmDs(Constants.APPROVED);
        try {
            am2.setAmAddtime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2012-11-16 16:32:23"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        am2.setArticleCid(1);
        am2.setArticleClass(articleClass);
        Am am3=new Am();
        am3.setAmId(3);
        am3.setAmAt("拼夕夕3");
        am3.setAmKw("夕夕3");
        am3.setAmWpd("这是一篇关于贪玩蓝月的文章");
        am3.setAmAc("贪玩蓝月你值得拥有");
        am3.setAmDs(Constants.PENDING);
        try {
            am2.setAmAddtime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2014-11-26 16:32:43"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        am3.setArticleCid(1);
        am3.setArticleClass(articleClass);
        ams.add(am1);
        ams.add(am2);
        ams.add(am3);
        responseData.setCode(Constants.SUCCESS);
        responseData.setMsg("查询成功");
        responseData.setData(ams);
        return responseData;
    }

    @GetMapping("queryArticleClass")
    @ApiOperation(value = "查询所有文章分类",notes = "查询所有文章分类",httpMethod = "GET", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=400,message="查询失败"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResponseData queryArticleClass(){
        List<ArticleClass> articleClasses=new ArrayList<>();
        ArticleClass articleClass1=new ArticleClass();
        articleClass1.setArticleCid(1);
        articleClass1.setArticleAs(Constants.APPROVED);
        articleClass1.setArticleCc("这是一个贪玩蓝月的广告");
        articleClass1.setArticleCname("贪玩蓝月");
        ArticleClass articleClass2=new ArticleClass();
        articleClass2.setArticleCid(2);
        articleClass2.setArticleAs(Constants.APPROVED);
        articleClass2.setArticleCc("这是一个传奇的广告");
        articleClass2.setArticleCname("传奇");
        ArticleClass articleClass3=new ArticleClass();
        articleClass3.setArticleCid(3);
        articleClass3.setArticleAs(Constants.PENDING);
        articleClass3.setArticleCc("这是一个王者荣耀的广告");
        articleClass3.setArticleCname("王者荣耀");
        articleClasses.add(articleClass1);
        articleClasses.add(articleClass2);
        articleClasses.add(articleClass3);
        responseData.setCode(Constants.SUCCESS);
        responseData.setMsg("查询成功");
        responseData.setData(articleClasses);
        return responseData;
    }

    @GetMapping("selectArticleByArticleClassNameAndArticleTitle")
    @ApiOperation(value = "根据文章类型名和文章标题查询文章",notes = "根据文章类型名和文章标题查询文章",httpMethod = "GET", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=400,message="查询失败"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleCname",value = "文章类型名称",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "amAt",value = "文章标题",paramType = "query",required = true,dataType = "String")
    })
    public ResponseData selectArticleByArticleClassNameAndArticleTitle(String articleCname, String amAt){
        System.out.println("articleCname="+articleCname+" amAt="+amAt);
        if (articleCname.equals("")||articleCname==null){
            responseData.setCode(Constants.FAILED);
            responseData.setMsg("查询失败");
            responseData.setData(null);
        }else if (amAt.equals("")||amAt==null){
            List<Am> ams=new ArrayList<>();
            ArticleClass articleClass=new ArticleClass();
            articleClass.setArticleCid(1);
            articleClass.setArticleAs(Constants.APPROVED);
            articleClass.setArticleCc("这是一个贪玩蓝月的广告");
            articleClass.setArticleCname(articleCname);
            Am am1=new Am();
            am1.setAmId(1);
            am1.setAmAt("拼夕夕1");
            am1.setAmKw("夕夕");
            am1.setAmWpd("这是一个拼夕夕的文章");
            am1.setAmAc("大嘎好！我系渣渣辉，贪玩蓝月一个非常好玩的游戏。装备回收秒到账，一刀999。开服即送麒麟坐骑，装备全靠打，是兄弟就来贪玩蓝月砍我");
            am1.setAmDs(Constants.APPROVED);
            am1.setArticleCid(1);
            am1.setArticleClass(articleClass);
            try {
                am1.setAmAddtime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2012-10-10 16:32:23"));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            Am am2=new Am();
            am2.setAmId(2);
            am2.setAmAt("拼夕夕2");
            am2.setAmKw("夕夕2");
            am2.setAmWpd("这是一个关于拼夕夕的文章");
            am2.setAmAc("大嘎好！我系古天乐，贪玩蓝月真的非常非常好玩。我和渣渣辉都在贪玩蓝月等你哦");
            am2.setAmDs(Constants.APPROVED);
            try {
                am2.setAmAddtime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2012-11-16 16:32:23"));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            am2.setArticleCid(1);
            am2.setArticleClass(articleClass);
            Am am3=new Am();
            am3.setAmId(3);
            am3.setAmAt("拼夕夕3");
            am3.setAmKw("夕夕3");
            am3.setAmWpd("这是一篇关于贪玩蓝月的文章");
            am3.setAmAc("贪玩蓝月你值得拥有");
            am3.setAmDs(Constants.PENDING);
            try {
                am2.setAmAddtime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2014-11-26 16:32:43"));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            am3.setArticleCid(1);
            am3.setArticleClass(articleClass);
            ams.add(am1);
            ams.add(am2);
            ams.add(am3);
            responseData.setCode(Constants.SUCCESS);
            responseData.setMsg("查询成功");
            responseData.setData(ams);
        }else {
            List<Am> ams=new ArrayList<>();
            ArticleClass articleClass=new ArticleClass();
            articleClass.setArticleCid(1);
            articleClass.setArticleAs(Constants.APPROVED);
            articleClass.setArticleCc("这是一个贪玩蓝月的广告");
            articleClass.setArticleCname(articleCname);
            Am am=new Am();
            am.setAmId(1);
            am.setAmAt(amAt);
            am.setAmKw("夕夕");
            am.setAmWpd("这是一个拼夕夕的文章");
            am.setAmAc("大嘎好！我系渣渣辉，贪玩蓝月一个非常好玩的游戏。装备回收秒到账，一刀999。开服即送麒麟坐骑，装备全靠打，是兄弟就来贪玩蓝月砍我");
            am.setAmDs(Constants.APPROVED);
            am.setArticleCid(1);
            am.setArticleClass(articleClass);
            try {
                am.setAmAddtime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2012-10-10 16:32:23"));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            ams.add(am);
            responseData.setCode(Constants.SUCCESS);
            responseData.setMsg("查询成功");
            responseData.setData(ams);
        }
        return responseData;
    }

    @GetMapping("selectArticleByArticleId")
    @ApiOperation(value = "根据文章主键查询文章",notes = "根据文章主键查询文章",httpMethod = "GET", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=400,message="查询失败"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "amId",value = "文章主键",paramType = "query",required = true,dataType = "Integer")
    })
    public ResponseData selectArticleByArticleId(Integer amId){
        System.out.println("amId="+amId);
        if (amId<=0){
            responseData.setCode(Constants.FAILED);
            responseData.setMsg("查询失败");
            responseData.setData(null);
        }else{
            ArticleClass articleClass=new ArticleClass();
            articleClass.setArticleCid(amId);
            articleClass.setArticleAs(Constants.APPROVED);
            articleClass.setArticleCc("这是一个贪玩蓝月的广告");
            articleClass.setArticleCname("贪玩蓝月");
            Am am1=new Am();
            am1.setAmId(1);
            am1.setAmAt("拼夕夕1");
            am1.setAmKw("夕夕");
            am1.setAmWpd("这是一个拼夕夕的文章");
            am1.setAmAc("大嘎好！我系渣渣辉，贪玩蓝月一个非常好玩的游戏。装备回收秒到账，一刀999。开服即送麒麟坐骑，装备全靠打，是兄弟就来贪玩蓝月砍我");
            am1.setAmDs(Constants.APPROVED);
            am1.setArticleCid(1);
            am1.setArticleClass(articleClass);
            try {
                am1.setAmAddtime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2012-10-10 16:32:23"));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            responseData.setCode(Constants.SUCCESS);
            responseData.setMsg("查询成功");
            responseData.setData(am1);
        }
        return responseData;
    }

    @PostMapping("updateArticle")
    @ApiOperation(value = "修改文章",notes = "修改文章",httpMethod = "POST", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="修改成功"),
            @ApiResponse(code=400,message="修改失败"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResponseData updateArticle(@RequestBody @ApiParam(name = "am",value = "文章实体",required = true) Am am) {
        System.out.println("am=" + am);
        if (!am.equals("")&&am!=null){
            responseData.setCode(Constants.SUCCESS);
            responseData.setMsg("修改成功");
            responseData.setData(null);
        }else {
            responseData.setCode(Constants.FAILED);
            responseData.setMsg("修改失败");
            responseData.setData(null);
        }
        return responseData;
    }

    @PostMapping("addArticle")
    @ApiOperation(value = "添加文章",notes = "添加文章",httpMethod = "POST", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="添加成功"),
            @ApiResponse(code=400,message="添加失败"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResponseData addArticle(@RequestBody @ApiParam(name = "am",value = "文章实体",required = true) Am am) {
        System.out.println("am=" + am);
        if (!am.equals("")&&am!=null){
            responseData.setCode(Constants.SUCCESS);
            responseData.setMsg("添加成功");
            responseData.setData(null);
        }else {
            responseData.setCode(Constants.FAILED);
            responseData.setMsg("添加失败");
            responseData.setData(null);
        }
        return responseData;
    }

    @GetMapping("deleteArticleByArticleId")
    @ApiOperation(value = "根据文章主键删除文章",notes = "根据文章主键删除文章",httpMethod = "GET", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="删除成功"),
            @ApiResponse(code=400,message="删除失败"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "amId",value = "文章主键",paramType = "query",required = true,dataType = "Integer")
    })
    public ResponseData deleteArticleByArticleId(Integer amId){
        System.out.println("amId="+amId);
        if (amId<=0){
            responseData.setCode(Constants.FAILED);
            responseData.setMsg("删除失败");
            responseData.setData(null);
        }else{
            responseData.setCode(Constants.SUCCESS);
            responseData.setMsg("删除成功");
            responseData.setData(null);
        }
        return responseData;
    }

    @GetMapping("deleteArticleByArticleIds")
    @ApiOperation(value = "根据文章主键数组删除文章",notes = "根据文章主键数组删除文章",httpMethod = "GET", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="删除成功"),
            @ApiResponse(code=400,message="删除失败"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "amIds",value = "文章主键数组",paramType = "query",required = true,dataType = "Integer")
    })
    public ResponseData deleteArticleByArticleIds(Integer[] amIds){
        System.out.println("amIds="+ Arrays.toString(amIds));
        if (amIds==null){
            responseData.setCode(Constants.FAILED);
            responseData.setMsg("删除失败");
            responseData.setData(null);
        }else{
            responseData.setCode(Constants.SUCCESS);
            responseData.setMsg("删除成功");
            responseData.setData(null);
        }
        return responseData;
    }

    @PostMapping("updateArticleClass")
    @ApiOperation(value = "修改文章类型",notes = "修改文章类型",httpMethod = "POST", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="修改成功"),
            @ApiResponse(code=400,message="修改失败"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResponseData updateArticleClass(@RequestBody @ApiParam(name = "articleClass",value = "文章类型实体",required = true) ArticleClass articleClass) {
        System.out.println("articleClass=" + articleClass);
        if (!articleClass.equals("")&&articleClass!=null){
            responseData.setCode(Constants.SUCCESS);
            responseData.setMsg("修改成功");
            responseData.setData(null);
        }else {
            responseData.setCode(Constants.FAILED);
            responseData.setMsg("修改失败");
            responseData.setData(null);
        }
        return responseData;
    }

    @GetMapping("queryAdvert")
    @ApiOperation(value = "查询所有广告",notes = "查询所有广告",httpMethod = "GET", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=400,message="查询失败"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResponseData queryAdvert(){
        List<Advert> adverts=new ArrayList<>();
        Advert advert1=new Advert();
        advert1.setAdvertId(1);
        advert1.setAdvertAdd("首页轮播广告位");
        try {
            advert1.setAdvertStart(new SimpleDateFormat("yyyy-MM-dd").parse("2020-11-27"));
            advert1.setAdvertLast(new SimpleDateFormat("yyyy-MM-dd").parse("2020-11-29"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        advert1.setOrder(20);
        advert1.setAdvertStatu(Constants.APPROVED);
        Advert advert2=new Advert();
        advert2.setAdvertId(2);
        advert2.setAdvertAdd("热播顶部广告位");
        try {
            advert2.setAdvertStart(new SimpleDateFormat("yyyy-MM-dd").parse("2020-11-28"));
            advert2.setAdvertLast(new SimpleDateFormat("yyyy-MM-dd").parse("2020-11-30"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        advert2.setOrder(30);
        advert2.setAdvertStatu(Constants.APPROVED);
        Advert advert3=new Advert();
        advert3.setAdvertId(3);
        advert3.setAdvertAdd("积分商城顶部广告位");
        try {
            advert3.setAdvertStart(new SimpleDateFormat("yyyy-MM-dd").parse("2020-12-04"));
            advert3.setAdvertLast(new SimpleDateFormat("yyyy-MM-dd").parse("2020-12-07"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        advert3.setOrder(50);
        advert3.setAdvertStatu(Constants.PENDING);
        adverts.add(advert1);
        adverts.add(advert2);
        adverts.add(advert3);
        responseData.setCode(Constants.SUCCESS);
        responseData.setMsg("查询成功");
        responseData.setData(adverts);
        return responseData;
    }

    @PostMapping("updateAdvert")
    @ApiOperation(value = "修改文章类型",notes = "修改文章类型",httpMethod = "POST", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="修改成功"),
            @ApiResponse(code=400,message="修改失败"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResponseData updateAdvert(@RequestBody @ApiParam(name = "advert",value = "广告实体",required = true) Advert advert) {
        System.out.println("advert=" + advert);
        if (!advert.equals("")&&advert!=null){
            responseData.setCode(Constants.SUCCESS);
            responseData.setMsg("修改成功");
            responseData.setData(null);
        }else {
            responseData.setCode(Constants.FAILED);
            responseData.setMsg("修改失败");
            responseData.setData(null);
        }
        return responseData;
    }

    @GetMapping("deleteAdvertByAdvertId")
    @ApiOperation(value = "根据广告主键删除广告",notes = "根据广告主键删除广告",httpMethod = "GET", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="删除成功"),
            @ApiResponse(code=400,message="删除失败"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "advertId",value = "广告主键",paramType = "query",required = true,dataType = "Integer")
    })
    public ResponseData deleteAdvertByAdvertId(Integer advertId){
        System.out.println("advertId="+advertId);
        if (advertId<=0){
            responseData.setCode(Constants.FAILED);
            responseData.setMsg("删除失败");
            responseData.setData(null);
        }else{
            responseData.setCode(Constants.SUCCESS);
            responseData.setMsg("删除成功");
            responseData.setData(null);
        }
        return responseData;
    }

    @PostMapping("addAdvert")
    @ApiOperation(value = "添加广告",notes = "添加广告",httpMethod = "POST", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="添加成功"),
            @ApiResponse(code=400,message="添加失败"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResponseData addAdvert(@RequestBody @ApiParam(name = "advert",value = "广告实体",required = true) Advert advert) {
        System.out.println("advert=" + advert);
        if (!advert.equals("")&&advert!=null){
            responseData.setCode(Constants.SUCCESS);
            responseData.setMsg("添加成功");
            responseData.setData(null);
        }else {
            responseData.setCode(Constants.FAILED);
            responseData.setMsg("添加失败");
            responseData.setData(null);
        }
        return responseData;
    }

}
